package com.weichen.studentgameexchange.game.controller;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.weichen.studentgameexchange.game.common.Result;
import com.weichen.studentgameexchange.game.entity.Sort;
import com.weichen.studentgameexchange.game.entity.UserGameGrade;
import com.weichen.studentgameexchange.game.entity.vo.GradeVo;
import com.weichen.studentgameexchange.game.service.IUserGameGradeService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 惟尘
 * @since 2025-02-01
 */
@RestController
@RequestMapping("/game/userGameGrade")
public class UserGameGradeController {

    @Autowired
    IUserGameGradeService userGameGradeService;

/**
 * TODO 用户-游戏--游戏评分
 */
    /**
     * 用户添加或修改游戏评分
     * @param userGameGrade
     * @return
     */
    @Operation(summary = "用户添加或修改游戏评分接口")
    @PostMapping("/user/addOrupdate")
    public Result userAddorUpdate(@RequestBody UserGameGrade userGameGrade){
        if (userGameGrade.getGradeId() == 0)
            userGameGradeService.save(userGameGrade);
        else
            userGameGradeService.updateById(userGameGrade);
        return Result.success();
    }

    /**
     * 用户查看游戏评分
     * @param userId
     * @param gameId
     * @return
     */
    @Operation(summary = "用户查看游戏评分接口")
    @GetMapping("/user/select")
    public Result userSelect(@RequestParam("userId") Long userId,@RequestParam("gameId") Long gameId){
        return userGameGradeService.userSelect(userId,gameId);
    }


/**
 * TODO 管理员-游戏--游戏评分管理
 */
    /**
     * 管理员分页查询评分信息
     * @param page
     * @param size
     * @return
     */
    @Operation(summary = "管理员分页查询评分信息接口")
    @GetMapping("/admin/page")
    public Result adminPage(@RequestParam(value = "page",defaultValue = "1") Integer page,
                            @RequestParam(value = "size",defaultValue = "5") Integer size){
        Page<GradeVo> gradeVoPage = userGameGradeService.adminPage(page, size);
        return Result.success(gradeVoPage);
    }

    /**
     * 管理员删除单个游戏评分
     * @param gradeId
     * @return
     */
    @Operation(summary = "管理员删除单个游戏评分接口")
    @DeleteMapping("/admin/delete/{gradeId}")
    public Result adminDeleteOne(@PathVariable("gradeId") Long gradeId){
        userGameGradeService.removeById(gradeId);
        return Result.success();
    }

    /**
     * 管理员批量删除多个游戏评分
     * @param gradeIds
     * @return
     */
    @Operation(summary = "管理员批量删除多个游戏评分接口")
    @DeleteMapping("/admin/delete/batch")
    public Result adminDeleteBatch(@RequestBody List<Long> gradeIds){
        userGameGradeService.removeBatchByIds(gradeIds);
        return Result.success();
    }
}
